package model

import (
	"fmt"
	"time"
)

type Book struct {
	Name string
	Total int
	Author string
	CreateDate time.Time
}

func CreateBook(name string, total int, author string, createDate time.Time) *Book {
	var b *Book = &Book{
		Name: name,
		Total: total,
		Author: author,
		CreateDate: createDate,
	}
	return b
}

func (b *Book) CanBorrow() bool {
	return b.Total > 0
}

func (b *Book) BorrowBook() {
	if b.CanBorrow() == false {
		fmt.Println("库存不足")
	}
	b.Total -= 1
}

func (b *Book) BackBook() {
	b.Total += 1
}